package xyz.scootaloo.oj.leetcode

import org.junit.Test
import xyz.scootaloo.oj.ds.ListNode

/**
 * @author flutterdash@qq.com
 * @since 2021/4/29 21:53
 */
class P160 {

    fun getIntersectionNode(headA: ListNode?, headB: ListNode?): ListNode? {
        if (headA == headB)
            return headA
        if (headA == null || headB == null)
            return null

        var A = headA
        var B = headB
        while (A != B) {
            A = if (A == null) headB else A.next
            B = if (B == null) headA else B.next
        }

        return A
    }

    @Test
    fun test0() {
        val node1a = ListNode(1)
        val node1b = ListNode(1)
        val node2 = ListNode(1)
        val node3 = ListNode(1)
        val node4 = ListNode(1)
        val node5 = ListNode(1)
        val node6 = ListNode(1)
    }

}
